package sicnu.cs.ich.token.security.exceptions;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.HttpClientErrorException;
import sicnu.cs.ich.api.common.ResultInfo;
import sicnu.cs.ich.api.common.enums.ResultEnum;
import sicnu.cs.ich.common.util.ResultInfoUtil;

/**
 * @author CaiKe
 * @date 2021/12/26 16:07
 */
@ControllerAdvice
@Slf4j
public class HttpClientExceptionHandler {

    @ExceptionHandler(HttpClientErrorException.class)
    @ResponseBody
    public ResultInfo<Void> handlerGlobalException(HttpClientErrorException exception) {
        log.error("Exception", exception);
        return ResultInfoUtil.buildError(ResultEnum.FORBIDDEN, exception.getLocalizedMessage());
    }

}